using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

using GonzalesCore.CoreElements;
using Kypris2.CoreManagers;
using Kypris2.CoreElements;

using Jamila2.CoreElements;
using Jamila2.Tools;
using Jamila2.Database;

namespace GonzalesCore.CoreManagers
{
    #region GLClaimTypeManager
    public class GLClaimTypeManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public GLClaimTypeManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        #region AddNewClaimType
        public bool AddNewClaimType(string Code, string Description)
        {
            bool smooth = true;
            ArrayList SQLList = new ArrayList();

            DatabaseParameters ValParameters = new DatabaseParameters();            
            ValParameters.Add (new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypes.ClaimTypeID.ActualFieldName, Code));
            ValParameters.Add (new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypes.Description.ActualFieldName, Description, true, true));
            this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.MasterClaimTypes.ActualTableName);
            SQLList.Add(this.CurSQLFactory.SQL);

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.SyncExpenseDetailInLocalLanguage.ActualTableName, null);
            SQLList.Add(this.CurSQLFactory.SQL);

            if (this.TryConnection())
            {

                if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLList)))
                {
                    this.ErrMsg = "[GLClaimTypeManager.AddNewClaimType] : Failed at this.CurDBEngine.ExecuteQuery()  : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[GLClaimTypeManager.AddNewClaimType] : Exception : " + this.ErrMsg;
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimTypeRelation
        public bool UpdateClaimTypeRelation(GLClaimTypes ExpenseDetails,  string EntityID)
        {
            bool smooth = true;
            ArrayList SQLList = new ArrayList();

            DatabaseParameters KeyParameters = new DatabaseParameters();
            DatabaseParameters ValParameters = new DatabaseParameters();

            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesRelation.EntityID.ActualFieldName, EntityID));
            this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.MasterClaimTypesRelation.ActualTableName);
            SQLList.Add(this.CurSQLFactory.SQL);

            foreach (GLClaimType ExpenseDeatil in ExpenseDetails)
            {
                ValParameters.Clear();

                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesRelation.ClaimTypeID.ActualFieldName, ExpenseDeatil.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesRelation.EntityID.ActualFieldName, EntityID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesRelation.CategoryID.ActualFieldName, ClaimManager.GetClaimCategoryInCode(ExpenseDeatil.Category).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesRelation.PerDiem.ActualFieldName, (ExpenseDeatil.PerDiem?"1":"0")));

                this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.MasterClaimTypesRelation.ActualTableName);
                SQLList.Add(this.CurSQLFactory.SQL);
            }

            if (this.TryConnection())
            {
                if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLList)))
                {
                    this.ErrMsg = "[GLClaimTypeManager.UpdateClaimTypeRelation] : Failed at this.CurDBEngine.ExecuteQuery : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[GLClaimTypeManager.UpdateClaimTypeRelation] : Exception : " + this.ErrMsg;
            }

            return smooth;
        }
        #endregion   

        #region UpdateClaimTypeInLocalLanguage
        public bool UpdateClaimTypeInLocalLanguage(GLClaimTypes ListOfExpenseDetailWithLocalLanguage, string SelectedLanguage)
        {
            bool smooth = true;
            ArrayList SQLList = new ArrayList();

            if (ListOfExpenseDetailWithLocalLanguage != null)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                foreach (GLClaimType CurrentClaimType in ListOfExpenseDetailWithLocalLanguage)
                {
                    KeyParameters.Clear();
                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLanguages.Language.ActualFieldName, SelectedLanguage));
                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLanguages.ClaimTypeID.ActualFieldName, CurrentClaimType.InternalID));

                    ValParameters.Clear();
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLanguages.Description.ActualFieldName, CurrentClaimType.DisplayName.Replace("'", "''"), true, true));

                    this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.MasterClaimTypesLanguages.ActualTableName);
                    SQLList.Add(this.CurSQLFactory.SQL);
                }

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLList)))
                    {
                        this.ErrMsg = "[GLClaimTypeManager.UpdateClaimTypeInLocalLanguage] : Failed at this.CurDBEngine.ExecuteQuery : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                else
                {
                    this.ErrMsg = "[GLClaimTypeManager.UpdateClaimTypeInLocalLanguage] : Exception : " + this.ErrMsg;
                }                
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region GetActiveClaimTypeInLangByEntity
        public MasterBaseCollection GetActiveClaimTypeInLangByEntity(Language LanguageInUsed, Entity EntityInUsed)
        {
            MasterBaseCollection ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Language.ActualFieldName, LanguageInUsed.InternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Entity.ActualFieldName, EntityInUsed.InternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Category.ActualFieldName, "99"));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.ActualTableName, KeyParameters);

            if (this.TryConnection())
            {
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new MasterBaseCollection();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        GLClaimType CurGLClaimType = new GLClaimType(
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.InternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.DisplayInLang.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.ClaimTypeID.ActualFieldName].ToString());

                        CurGLClaimType.Category = ClaimManager.GetClaimCategoryFromCode(ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Category.ActualFieldName].ToString());
                        CurGLClaimType.ActualName = ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.ExpenseName.ActualFieldName].ToString();
                        CurGLClaimType.PerDiem = (ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.PerDiem.ActualFieldName].ToString().CompareTo("1") == 0);

                        ResultCollection.Add(CurGLClaimType);
                    }
                }
                else
                {
                    this.ErrMsg = "[GLClaimTypeManager.GetActiveClaimTypeInLangByEntity] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[GLClaimTypeManager.GetActiveClaimTypeInLangByEntity] : Exception : " + this.ErrMsg;
            }

            return ResultCollection;
        }

        public MasterBaseCollection GetActiveClaimTypeInLangByEntity(Language LanguageInUsed, Entity EntityInUsed, string CategoryID)
        {
            MasterBaseCollection ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Language.ActualFieldName, LanguageInUsed.InternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Entity.ActualFieldName, EntityInUsed.InternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.Param_Category.ActualFieldName, CategoryID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.ActualTableName, KeyParameters);

            if (this.TryConnection())
            {
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new MasterBaseCollection();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        GLClaimType CurGLClaimType = new GLClaimType(
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.InternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.DisplayInLang.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetActiveClaimTypeInLangByEntity.ClaimTypeID.ActualFieldName].ToString());

                        CurGLClaimType.Category = ClaimManager.GetClaimCategoryFromCode(CategoryID);

                        ResultCollection.Add(CurGLClaimType);
                    }
                }
            }

            return ResultCollection;
        }
        #endregion        

        #region GetAllClaimTypeInLang
        public MasterBaseCollection GetAllClaimTypeInLang(Language LanguageInUsed)
        {
            MasterBaseCollection ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.MasterClaimType.Language.ActualFieldName, LanguageInUsed.InternalID));

            this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Views.MasterClaimType.ActualTableName);

            if (this.TryConnection())
            {
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new MasterBaseCollection();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        GLClaimType CurrentGL = new GLClaimType(
                            ResultRow[this.DataStructrure.Views.MasterClaimType.InternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Views.MasterClaimType.DisplayInLang.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Views.MasterClaimType.ClaimTypeID.ActualFieldName].ToString());
                        CurrentGL.ActualName = ResultRow[this.DataStructrure.Views.MasterClaimType.Description.ActualFieldName].ToString();

                        ResultCollection.Add(CurrentGL);
                    }
                }
            }

            return ResultCollection;
        }
        #endregion

        #region QueryMasterGLClaimType
        protected DataTable QueryMasterGLClaimType(DatabaseParameters KeyParameters)
        {
            DataTable ResultTable = null;

            if (this.TryConnection())
            {
                try
                {
                    this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Tables.MasterClaimTypes.Name);
                    ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                }
                catch (Exception ex)
                {
                    this.ErrMsg = ex.Message;
                }

            }

            return ResultTable;
        }
        #endregion

        #region Claim Type Limit

        #region GetClaimTypeLimitByClaimant
        public MasterBaseCollection GetClaimTypeLimitByClaimant(string ClaimantInternalID, string LanguageID)
        {
            MasterBaseCollection ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Param_ClaimantID.ActualFieldName, ClaimantInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Param_LanguageID.ActualFieldName, LanguageID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultCollection = new MasterBaseCollection();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        GLClaimType ResultObj = new GLClaimType(
                            ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.InternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Description.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.ClaimTypeID.ActualFieldName].ToString());

                        ResultObj.ClaimLimit = decimal.Parse(ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitAmount.ActualFieldName].ToString());
                        ResultObj.ClaimLimitCurrency = ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitCurrency.ActualFieldName].ToString();
                        ResultObj.LimitDuration =
                            ClaimManager.GetClaimTypeLimitDurationFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitDuration.ActualFieldName]));
                        ResultObj.Strict = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Strict.ActualFieldName].ToString().CompareTo("1") == 0);

                        ResultCollection.Add(ResultObj);
                    }
                }
            }


            return ResultCollection;
        }

        #endregion

        #region GetClaimTypeLimitByClaimant
        public DataTable GetClaimTypeLimitByCompany(string Company)
        {
            DataTable ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.ClaimTypeLimit.Company.ActualFieldName, Company));

            if (this.TryConnection())
            {
                this.CurSQLFactory.SelectCommand(KeyParameters,this.DataStructrure.Views.ClaimTypeLimit.ActualTableName);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultCollection = ResultTable;

                    //foreach (DataRow ResultRow in ResultTable.Rows)
                    //{
                    //    GLClaimType ResultObj = new GLClaimType(
                    //        ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.InternalID.ActualFieldName].ToString(),
                    //        ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Description.ActualFieldName].ToString(),
                    //        ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.ClaimTypeID.ActualFieldName].ToString());

                    //    ResultObj.ClaimLimit = decimal.Parse(ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitAmount.ActualFieldName].ToString());
                    //    ResultObj.ClaimLimitCurrency = ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitCurrency.ActualFieldName].ToString();
                    //    ResultObj.LimitDuration =
                    //        ClaimManager.GetClaimTypeLimitDurationFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.LimitDuration.ActualFieldName]));
                    //    ResultObj.Strict = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimTypeLimitInLangByClaimantID.Strict.ActualFieldName].ToString().CompareTo("1") == 0);

                    //    ResultCollection.Add(ResultObj);
                    //}
                }
            }


            return ResultCollection;
        }

        #endregion

        #region AddClaimTypeLimit
        public bool AddClaimTypeLimit(string ClaimantID, string ClaimTypeID, string Currency, decimal Amount, int Duration, bool Strict)
        {
            bool smooth = true;

            DatabaseParameters ValParameters = new DatabaseParameters();
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeID.ActualFieldName, ClaimTypeID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeUser.ActualFieldName, ClaimantID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitAmount.ActualFieldName, Amount.ToString()));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitCurrency.ActualFieldName, Currency));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitDuration.ActualFieldName, Duration.ToString()));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.Strict.ActualFieldName, (Strict?"1":"0")));

            this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.MasterClaimTypesLimit.ActualTableName);

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = "[GLClaimTypeManager.AddClaimTypeLimit] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }

            }

            return smooth;
        }

        public bool AddClaimTypeLimit(ArrayList DataList, string CompanyID)
        {
            bool smooth = true;
            string[] sql = new string[DataList.Count];

            string SessionID = SwissArmy.UniqueID();

            DatabaseParameters ValParameters = null;

            for (int x = 0; x < DataList.Count; x++)
            {
                string[] LineText = (string[])DataList[x];

                ValParameters = new DatabaseParameters();

                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.SessionID.ActualFieldName, SessionID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.ClaimTypeID.ActualFieldName, LineText[3].Replace("\"","")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.ClaimTypeDesc.ActualFieldName, LineText[2].Replace("\"", "")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.ClaimTypeUser.ActualFieldName, LineText[1].Replace("\"", "")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.LimitAmount.ActualFieldName, LineText[5].Replace("\"", "")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.LimitCurrency.ActualFieldName, LineText[4].Replace("\"", "")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.LimitDuration.ActualFieldName, LineText[6].Replace("\"", "")));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.TempClaimTypesLimit.Strict.ActualFieldName, LineText[7].Replace("\"", "")));

                this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.TempClaimTypesLimit.ActualTableName);

                sql[x] = this.CurSQLFactory.SQL;
            }

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(sql);
                if (!smooth)
                {
                    this.ErrMsg = "[GLClaimTypeManager.AddClaimTypeLimit] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
                else
                {
                    ValParameters = new DatabaseParameters();
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.BatchUpdateExceptionalExpenseLimit.Param_CompanyID.ActualFieldName, CompanyID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.BatchUpdateExceptionalExpenseLimit.Param_SessionID.ActualFieldName, SessionID));

                    this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.BatchUpdateExceptionalExpenseLimit.ActualTableName, ValParameters);
                    DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                    if (ResultTable != null && ResultTable.Rows.Count == 1)
                    {
                        string ResultMessage = ResultTable.Rows[0][this.DataStructrure.StoredProcedures.BatchUpdateExceptionalExpenseLimit.ResponseMessage.ActualFieldName].ToString();
                        if (ResultMessage.CompareTo("SUCCESS") != 0)
                        {
                            smooth = false;
                            this.ErrMsg = ResultMessage;
                        }
                    }
                }

            }

            return smooth;
        }
        #endregion

        #region UpdateClaimTypeLimit
        public bool UpdateClaimTypeLimit(string ClaimantID, string ClaimTypeID, string Currency, decimal Amount, int Duration, bool Strict)
        {
            bool smooth = true;

            DatabaseParameters ValParameters = new DatabaseParameters();
            DatabaseParameters KeyParameters = new DatabaseParameters();

            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeID.ActualFieldName, ClaimTypeID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeUser.ActualFieldName, ClaimantID));

            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitAmount.ActualFieldName, Amount.ToString()));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitCurrency.ActualFieldName, Currency));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.LimitDuration.ActualFieldName, Duration.ToString()));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.Strict.ActualFieldName, (Strict ? "1" : "0")));

            this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.MasterClaimTypesLimit.ActualTableName);

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = "[GLClaimTypeManager.UpdateClaimTypeLimit] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }

            }

            return smooth;
        }
        #endregion

        #region DeleteClaimTypeLimit
        public bool DeleteClaimTypeLimit(string ClaimantID, string ClaimTypeID)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeID.ActualFieldName, ClaimTypeID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypesLimit.ClaimTypeUser.ActualFieldName, ClaimantID));

            this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.MasterClaimTypesLimit.ActualTableName);

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = "[GLClaimTypeManager.DeleteClaimTypeLimit] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }

            }

            return smooth;
        }
        #endregion

        #endregion

        #region DeleteClaimType

        public bool DeleteClaimTypeByID(string ClaimTypeID)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterClaimTypes.InternalID.ActualFieldName, ClaimTypeID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.MasterClaimTypes.ActualTableName);

                if (!(smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL)))
                {
                    this.ErrMsg = "[GLClaimTypeManager.DeleteClaimTypeByID] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
                this.ErrMsg = "[GLClaimTypeManager.DeleteClaimTypeByID] : Exception : " + this.CurDBEngine.ErrorMessage;
            }

            return smooth;
        }

        #endregion
    }

    #endregion

    #region LanguageManager
    public class LanguageManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public LanguageManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        #region GetAllLanguage
        public MasterBaseCollection GetAllLanguage()
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();

            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Views.MasterLanguages.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Language NewLanguage = new Language(ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageName.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.InternalID.ActualFieldName].ToString());
                    NewLanguage.State = (ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString().CompareTo("1") == 0);

                    ResultList.Add(NewLanguage);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("LanguageManager.GetAllLanguage : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }

        public MasterBaseCollection GetAllLanguage(bool State)
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.MasterLanguages.State.ActualFieldName, (State?"1":"0")));

            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Views.MasterLanguages.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Language NewLanguage = new Language(ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageName.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.InternalID.ActualFieldName].ToString());
                    NewLanguage.State = (ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString().CompareTo("1") == 0);

                    ResultList.Add(NewLanguage);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("LanguageManager.GetAllLanguage : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }
        #endregion

        #region GetAllLanguageInOrder
        public MasterBaseCollection GetAllLanguageInOrder()
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();

            // add in sorting mechanism
            DatabaseParameters SortParameters = new DatabaseParameters();
            DatabaseParameter SortByOrder = new DatabaseParameter(this.DataStructrure.Views.MasterLanguages.Order.ActualFieldName, "");
            SortByOrder.SortBy = SortByOrder.ASC = true;
            SortParameters.Add(SortByOrder);

            DataTable ResultTable = this.QueryData(KeyParameters, SortParameters, this.DataStructrure.Views.MasterLanguages.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Language NewLanguage = new Language(ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageName.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.InternalID.ActualFieldName].ToString());
                    NewLanguage.State = (ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString().CompareTo("1") == 0);

                    ResultList.Add(NewLanguage);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("LanguageManager.GetAllLanguage : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }

        public MasterBaseCollection GetAllLanguageInOrder(bool State)
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.MasterLanguages.State.ActualFieldName, (State?"1":"0")));

            // add in sorting mechanism
            DatabaseParameters SortParameters = new DatabaseParameters();
            DatabaseParameter SortByOrder = new DatabaseParameter(this.DataStructrure.Views.MasterLanguages.Order.ActualFieldName, "");
            SortByOrder.SortBy = SortByOrder.ASC = true;
            SortParameters.Add(SortByOrder);

            DataTable ResultTable = this.QueryData(KeyParameters, SortParameters, this.DataStructrure.Views.MasterLanguages.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Language NewLanguage = new Language(ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageName.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterLanguages.InternalID.ActualFieldName].ToString());
                    NewLanguage.State = (ResultRow[this.DataStructrure.Views.MasterLanguages.LanguageID.ActualFieldName].ToString().CompareTo("1") == 0);

                    ResultList.Add(NewLanguage);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("LanguageManager.GetAllLanguage : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }
        #endregion

    }
    #endregion

    #region CurrencyManager
    public class CurrencyManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public CurrencyManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        #region GetAllCurrency
        public MasterBaseCollection GetAllCurrency()
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();
            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Views.MasterDistinctCurrency.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Currency NewCurrency = new Currency(ResultRow[this.DataStructrure.Views.MasterDistinctCurrency.CurrencyCode.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Views.MasterDistinctCurrency.CurrencyCode.ActualFieldName].ToString());

                    ResultList.Add(NewCurrency);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("CurrencyManager.GetAllCurrency : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }
        #endregion

        #region GetLatestExchangeRate
        public MasterBaseCollection GetLatestExchangeRate(Currency SourceCurrency)
        {
            MasterBaseCollection ResultList = null;

            if (SourceCurrency != null)
            {
                if (this.TryConnection())
                {
                    DatabaseParameters KeyParameters = new DatabaseParameters();
                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Param_SourceCurrency.ActualFieldName, SourceCurrency.InternalID));
                    this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.ActualTableName, KeyParameters);

                    DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL); ;
                    if (ResultTable != null)
                    {
                        ResultList = new MasterBaseCollection();

                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            Currency CurCurrency = new Currency(
                                ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Source.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Source.ActualFieldName].ToString(),
                                float.Parse(ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Rate.ActualFieldName].ToString()));

                            ResultList.Add(CurCurrency);

                        }
                    }
                    else
                    {
                        // log error   
                        this.CurrentLogManager.LogError("CurrencyManager.GetLatestExchangeRate : " + this.CurDBEngine.ErrorMessage, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
                    }
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("CurrencyManager.GetLatestExchangeRate : Source Currency", this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }
            
            return ResultList;
        }
        #endregion

        #region GetExchangeRateByDate
        public MasterBaseCollection GetExchangeRateByDate(DateTime SpecificDate, string TargetCurrency)
        {
            MasterBaseCollection ResultCollection = null;

            if (TargetCurrency.Length == 3)
            {
                if (this.TryConnection())
                {
                    DatabaseParameters KeyParameters = new DatabaseParameters();
                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetExchangeRateByTargetCurrency.Param_SpecificDate.ActualFieldName, SpecificDate));
                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetExchangeRateByTargetCurrency.Param_TargetCurrency.ActualFieldName, TargetCurrency));

                    this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetExchangeRateByTargetCurrency.ActualTableName, KeyParameters);
                    DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                    if (ResultTable != null)
                    {
                        ResultCollection = new MasterBaseCollection();

                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            Currency CurCurrency = new Currency(
                                ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Source.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Source.ActualFieldName].ToString(),
                                float.Parse(ResultRow[this.DataStructrure.StoredProcedures.GetLatestExchangeRateBySourceCurrency.Rate.ActualFieldName].ToString()));

                            ResultCollection.Add(CurCurrency);

                        }
                    }
                    else
                    {
                        this.ErrMsg = "[CurrencyManager.GetExchangeRateByDate] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                else
                {
                    this.ErrMsg = "[CurrencyManager.GetExchangeRateByDate] : Exception : " + this.ErrMsg;
                }

            }

            return ResultCollection;
        }
        #endregion

        public override void Dispose()
        {
            CurrentLogManager = null;

            base.Dispose();
        }

    }

    #endregion

    #region CountryManager
    public class CountryManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public CountryManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        #region GetAllCountry

        public MasterBaseCollection GetAllCountry()
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();
            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Tables.MasterCountry.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Country NewCountry = new Country(ResultRow[this.DataStructrure.Tables.MasterCountry.CountryCode.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Tables.MasterCountry.CountryName.ActualFieldName].ToString(),
                        (new Currency(ResultRow[this.DataStructrure.Tables.MasterCountry.AllowanceCurrency.ActualFieldName].ToString(), ResultRow[this.DataStructrure.Tables.MasterCountry.AllowanceCurrency.ActualFieldName].ToString())),
                        Convert.ToDouble(ResultRow[this.DataStructrure.Tables.MasterCountry.Allowance.ActualFieldName].ToString()),
                        (new Currency(ResultRow[this.DataStructrure.Tables.MasterCountry.DefaultCurrency.ActualFieldName].ToString(), ResultRow[this.DataStructrure.Tables.MasterCountry.DefaultCurrency.ActualFieldName].ToString())));

                    ResultList.Add(NewCountry);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("CurrencyManager.GetAllCurrency : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }

        #endregion

        public override void Dispose()
        {
            CurrentLogManager = null;

            base.Dispose();
        }

    }

    #endregion

    #region EntityManager
    public class EntityManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public EntityManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        #region GetAllEntity
        public MasterBaseCollection GetAllEntity()
        {
            MasterBaseCollection ResultList = null;
            DatabaseParameters KeyParameters = new DatabaseParameters();

            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Tables.MasterEntity.ActualTableName);

            if (ResultTable != null)
            {
                ResultList = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Entity NewEntity = new Entity(ResultRow[this.DataStructrure.Tables.MasterEntity.ID.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.Tables.MasterEntity.EntityName.ActualFieldName].ToString(),
                        Convert.ToInt32(ResultRow[this.DataStructrure.Tables.MasterEntity.Order.ActualFieldName].ToString()));                    

                    NewEntity.BPCS = ResultRow[this.DataStructrure.Tables.MasterEntity.BPCS.ActualFieldName].ToString();

                    ResultList.Add(NewEntity);
                }
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("EntityManager.GetAllEntity : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultList;
        }
        #endregion

        #region GetEntityDetailByCode
        public Entity GetEntityDetailByCode(string EntityCode)
        {
            Entity ResultObj = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterEntity.ID.ActualFieldName, EntityCode.ToString()));

            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Tables.MasterEntity.ActualTableName);

            if (ResultTable != null && ResultTable.Rows.Count == 1)
            {
                DataRow ResultRow = ResultTable.Rows[0];

                ResultObj = new Entity(
                    ResultRow[this.DataStructrure.Tables.MasterEntity.ID.ActualFieldName].ToString(),
                    ResultRow[this.DataStructrure.Tables.MasterEntity.EntityName.ActualFieldName].ToString(),
                    Convert.ToInt32(ResultRow[this.DataStructrure.Tables.MasterEntity.Order.ActualFieldName].ToString()));                

                ResultObj.BPCS = ResultRow[this.DataStructrure.Tables.MasterEntity.BPCS.ActualFieldName].ToString();
            }
            else
            {
                // log error   
                this.CurrentLogManager.LogError("EntityManager.GetEntityDetail : " + this.ErrMsg, this.PrivateConfig.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultObj;
        }        
        #endregion

        #region UpdateEntity

        public bool UpdateEntity(Entity CurEntity)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterEntity.ID.ActualFieldName, CurEntity.InternalID));

            DatabaseParameters ValParameters = new DatabaseParameters();
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterEntity.EntityName.ActualFieldName, CurEntity.DisplayName));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterEntity.BPCS.ActualFieldName, CurEntity.BPCS));            
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterEntity.Order.ActualFieldName, CurEntity.Order.ToString()));

            this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.MasterEntity.ActualTableName);

            if (this.TryConnection())
            {
                if (!(smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL)))
                {
                    this.ErrMsg = "[EntityManager.UpdateEntity] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            } 

            return smooth;
        }

        #endregion

    }
    #endregion

    #region ProjectManager
    public class ProjectManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private new PersonalSessionAccount PrivateConfig = null;
        private LogManager CurrentLogManager = null;

        public ProjectManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.PrivateConfig = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }        

        #region GetProjectsByEntityCode
        public MasterBaseCollection GetProjectByEntityCode(string EntityCode)
        {
            MasterBaseCollection ResultObj = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterProject.EntityID.ActualFieldName, EntityCode));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.MasterProject.Active.ActualFieldName, "1"));

            DataTable ResultTable = this.QueryData(KeyParameters, this.DataStructrure.Tables.MasterProject.ActualTableName);

            if (ResultTable != null)
            {
                ResultObj = new MasterBaseCollection();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    Project CurProject = new Project(ResultRow[this.DataStructrure.Tables.MasterProject.ProjectID.ActualFieldName].ToString());
                    CurProject.EntityID = ResultRow[this.DataStructrure.Tables.MasterProject.EntityID.ActualFieldName].ToString();
                    CurProject.ProjectID = ResultRow[this.DataStructrure.Tables.MasterProject.ProjectID.ActualFieldName].ToString();
                    CurProject.ProjectDescription = ResultRow[this.DataStructrure.Tables.MasterProject.ProjectDescription.ActualFieldName].ToString();
                    CurProject.ProjectType = ResultRow[this.DataStructrure.Tables.MasterProject.ProjectType.ActualFieldName].ToString();
                    CurProject.State = (ResultRow[this.DataStructrure.Tables.MasterProject.Active.ActualFieldName].ToString().CompareTo("1") == 0);

                    ResultObj.Add(CurProject);
                }

            }
            else
            {
                // log error   
                this.ErrMsg = "[ProjectManager.GetProjectByEntityCode] : Failed at this.QueryData() : " + this.ErrMsg;
            }

            return ResultObj;
        }
        #endregion

    }
    #endregion

}
